<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${basePath}css/font.css">
    <link rel="stylesheet" href="${basePath}css/xadmin.css">
    <script type="text/javascript" src="${basePath}js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="${basePath}lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${basePath}js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="${basePath}css/xcConfirm.css" type="text/css">
    <script src="${basePath}js/xcConfirm.js"></script>
    <script src="${basePath}lib/My97DatePicker/WdatePicker.js"></script>
</head>
<script>
    $(function () {
        try {
            var index = parent.layer.getFrameIndex(window.name);
            window.parent.location.reload();
            parent.layer.close(index);
        } catch (e) {

        }
    });
</script>
<body>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane" method="get">
            <input class="layui-input" placeholder="手机号" name="telephone" value="${page.conMap.telephone}">
            <input class="layui-input" placeholder="订单编号" name="orderCode" value="${page.conMap.orderCode}">
            <input class="layui-input" placeholder="订单渠道" name="userSource" value="${page.conMap.userSource}">
            <input class="layui-input" placeholder="订单支付时间-开始" name="orderBeginTime"
                   value="${page.conMap.orderBeginTime}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <input class="layui-input" placeholder="订单支付时间-结束" name="orderEndTime" value="${page.conMap.orderEndTime}"
                   onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
            <span>订单状态</span>
            <input type="checkbox" name="orderStatus" value="1" id="orderStatus1"/> 待付款
            <input type="checkbox" name="orderStatus" value="2" id="orderStatus2"/> 待收货
            <input type="checkbox" name="orderStatus" value="3" id="orderStatus3"/> 待评价
            <input type="checkbox" name="orderStatus" value="4" id="orderStatus4"/> 已完成
            <input type="checkbox" name="orderStatus" value="5" id="orderStatus5"/> 取消订单
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="exportExcel()">
            <i class="layui-icon"></i>订单导出
        </button>
        <span class="x-right" style="line-height:40px">共有数据：${page.totalCount} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <td>序号</td>
            <td>订单编号</td>
            <td>支付单号</td>
            <td>订单状态</td>
            <td>支付时间</td>
            <td>渠道</td>
            <td>手机号</td>
            <td>购买课程名称</td>
            <td>全场活动</td>
            <td>使用优惠券</td>
            <td>原铜钱消耗</td>
            <td>新铜钱消耗</td>
            <td>使用金币</td>
            <td>新金币</td>
            <td>订单总额</td>
            <td>实际支付</td>
            <td>订单标识</td>
            <td>订单详情</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <c:if test="${not empty page.results}">
            <c:forEach items="${page.results}" var="result" varStatus="vs">
                <tr>
                    <td>${(page.actulPageNo - 1) * 15 + vs.count}</td>
                    <td><a class="orderAttr" style="corsor:pointer"
                           onclick="showDetails('${result.orderCode}')">${result.orderCode}</a></td>
                    <td>${result.transaction_id}</td>
                    <td>
                        <c:if test="${result.orderStatus eq '1'}">待付款</c:if>
                        <c:if test="${result.orderStatus eq '2'}">待收货</c:if>
                        <c:if test="${result.orderStatus eq '3'}">待评价</c:if>
                        <c:if test="${result.orderStatus eq '4'}">已完成</c:if>
                        <c:if test="${result.orderStatus eq '5'}">取消订单</c:if>
                        <c:if test="${result.orderStatus eq '6'}"><font style="color:red;">已退货</font></c:if>
                    </td>
                    <td>${result.orderPayTime}</td>
                    <td>${result.userSource}</td>
                    <td>${result.telephone}</td>
                    <td>${result.goodsNames}</td>
                    <td>${result.activityInfo }</td>
                    <td>${result.title}</td>
                    <td>${result.oldCopperCash}</td>
                    <td>${result.newCopperCash}</td>
                    <td>${result.gold}</td>
                    <td>${result.newGold}</td>
                    <td>${result.goodsAmount}</td>
                    <td>${result.orderAmount}</td>
                    <td>${result.identification}</td>
                    <td>
                        <button class="layui-btn layui-btn layui-btn-xs"
                                onclick="x_admin_show('订单详情','${basePath}goodsOrder/pageLoad/${result.orderCode}_1')">
                            <i class="layui-icon">&#xe642;</i>订单详情
                        </button>
                    </td>
                    <td>
                        <c:choose>
                            <c:when test="${result.orderStatus eq '4'}">
                                <button class="layui-btn layui-btn-warm layui-btn-xs"
                                        onclick="returnOrder('${result.orderCode}')"><i class="layui-icon">&#xe642;</i>退货
                                </button>
                            </c:when>
                            <c:otherwise>——</c:otherwise>
                        </c:choose>
                    </td>
                </tr>
            </c:forEach>
        </c:if>
        </tbody>
    </table>
    <div class="page">
        <c:if test="${page.totalPageNo > 1 }">
            <div>
                <a class="num" href='${basePath}${page.url}?pageNo=1${page.params}'>首页</a>
                <c:if test="${page.actulPageNo > 1 }">
                    <a class="prev"
                       href='${basePath}${page.url}?pageNo=${page.actulPageNo - 1}${page.params}'>上一页</a>
                </c:if>
                <c:forEach var="pno" items="${page.showNums }">
                    <c:choose>
                        <c:when test="${pno == page.actulPageNo}">
                            <span class="current"> ${pno }</span>
                        </c:when>
                        <c:otherwise>
                            <c:if test="${not empty pno}">
                                <a class="num"
                                   href='${basePath}${page.url}?pageNo=${pno  }${page.params}'>${pno }</a>
                            </c:if>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
                <c:if test="${page.actulPageNo  < page.totalPageNo }">
                    <a class="next" href='${basePath}${page.url}?pageNo=${page.actulPageNo + 1}${page.params}'>下一页</a>
                </c:if>
                <a class="num" href='${basePath}${page.url}?pageNo=${page.totalPageNo }${page.params}'>尾页</a>
            </div>
        </c:if>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        form = layui.form;

    });

    function returnOrder(id) {
        layer.confirm('确定要退货吗?退货后铜钱、优惠券将原路返回给用户！！！', function () {
            var url = "${basePath}goodsOrder/goodsReturn/" + id;
            location.href = url;
        });
    }

    function showDetails(orderCode) {
        $.ajax({
            url: '${basePath}goodsOrder/queryOrderDetails',
            data: {"orderCode": orderCode},
            type: 'get',
            dataType: 'text',
            success: function (data) {
                if (data.length > 0) {
                    var w = JSON.parse(data);
                    var txt = '该订单包括：</br>';
                    for (var i = 0, wLength = w.length; i < wLength; i++) {
                        txt += w[i].goodsName + "</br>";
                    }
                    txt += '等商品';
                    window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
                }
            }
        });
    };

    $(function () {
        $(".orderAttr").mouseover(function () {
            var orderCode = $(this).html();
            var result;
            $.ajax({
                url: '${basePath}goodsOrder/queryOrderDetails',
                async: false,
                data: {"orderCode": orderCode},
                type: 'get',
                dataType: 'text',
                success: function (data) {
                    if (data.length > 0) {
                        var txt = '该订单包括：';
                        var w = JSON.parse(data);
                        for (var i = 0, wLength = w.length; i < wLength; i++) {
                            txt += ("【" + w[i].goodsName + "】");
                        }
                        txt += '等商品';
                        result = txt;

                    }
                }
            });
            $(this).attr("title", result);
        });
    });

    $(function () {
        var s = document.getElementsByName("orderStatus");//所有复选框的值
        var statusList = '${page.conMap.statusList }';//查询条件勾选的值
        if (statusList != null && statusList != "") {
            statusList = statusList.replace("[", "").replace("]", "");
            var arr = statusList.split(',');

            for (var j = 0; j < arr.length; j++) {
                if (arr[j] == 1) {
                    $('#orderStatus1').attr('checked', true);
                }
                if (arr[j] == 2) {
                    $('#orderStatus2').attr('checked', true);
                }
                if (arr[j] == 3) {
                    $('#orderStatus3').attr('checked', true);
                }
                if (arr[j] == 4) {
                    $('#orderStatus4').attr('checked', true);
                }
                if (arr[j] == 5) {
                    $('#orderStatus5').attr('checked', true);
                }
            }
        }
        if ('${roleName}' == 'orderExport') {
            $("#export1").show();
            $("#export2").hide();
        }
    });

    function exportExcel() {
        var orderCode = $("input[name='orderCode']").val();
        var telephone = $("input[name='telephone']").val();
        var userSource = $("input[name='userSource']").val();
        var orderBeginTime = $("input[name='orderBeginTime']").val();
        var orderEndTime = $("input[name='orderEndTime']").val();
        var orderStatus = "";
        $('input[type="checkbox"][name="orderStatus"]:checked').each(
            function () {
                orderStatus = orderStatus + "," + $(this).val();
            });
        var params = "orderCode=" + orderCode
            + "&telephone=" + telephone
            + "&orderStatus=" + orderStatus
            + "&userSource=" + userSource
            + "&orderBeginTime=" + orderBeginTime
            + "&orderEndTime=" + orderEndTime;
        var url = "${basePath}goodsOrder/exportExcel?" + params;
        window.location.href = url;
    }
</script>
</body>

</html>